<%inherit file="base.html"/>
<h2>Peerscape Admin</h2>
<div class="section" id="info">
    <h3>Browse data</h3>
    <div class="intro">
        <p>Browse the data that is currently stored on your computer.</p>
    </div>

    <div id="dataBrowser">
        <h3>Person</h3>
        <ul id="person">
        % for iid, ds in dataset_list['principal'].items():
            <li id="i${iid}">
                <a href="http://admin.hexlabel.net/browse_db/${iid}#${iid}">${ds['name']}</a>
                <div class="meta">touched: ${ds['info']['touched']}, size: ${ds['info']['size']}</div>
                % if dataset_iid and dataset_iid == iid:
                    <ul>
                        <li>
                            INFO: ${procDICT(iid, dataset['info'], no_links=True)}
                        </li>
                        <li>
                            DATA
                            <ul>
                                % for k, v in dataset['data'].items():
                                    <li>
                                        % if type(v) == type(dict()):
                                            <h4>${k}</h4>
                                            ${procDICT(iid, v, no_links=True)}
                                        % elif type(v) == type(list()):
                                            <h4>${k}</h4>
                                            ${procLIST(v)}
                                        % else:
                                            % if v:
                                                <h4><a href="http://${iid}.hexlabel.net/content/${k}">${k}</a></h4>
                                                ${v}
                                            % else:
                                                <h4>${k}</h4>
                                                None
                                            % endif
                                        % endif
                                    </li>
                                % endfor
                                % if len(dataset['keys']) == 0:
                                    Empty
                                % endif
                            </ul>
                        </li>
                    </ul>
                % endif
            </li>
        % endfor
        </ul>

        <h3>Group</h3>
        <ul id="group">
        % for iid, ds in dataset_list['group'].items():
            <li id="i${iid}">
                <a href="http://admin.hexlabel.net/browse_db/${iid}#${iid}">${ds['name']}</a>
                <div class="meta">touched: ${ds['info']['touched']}, size: ${ds['info']['size']}</div>
                % if dataset_iid and dataset_iid == iid:
                    <ul>
                        <li>
                            INFO: ${procDICT(iid, dataset['info'], no_links=True)}
                        </li>
                        <li>
                            DATA
                            <ul>
                                % for k, v in dataset['data'].items():
                                    <li>
                                        % if type(v) == type(dict()):
                                            <h4>${k}</h4>
                                            ${procDICT(iid, v, no_links=True)}
                                        % elif type(v) == type(list()):
                                            <h4>${k}</h4>
                                            ${procLIST(v)}
                                        % else:
                                            % if v:
                                                <h4><a href="http://${iid}.hexlabel.net/content/${k}">${k}</a></h4>
                                                ${v}
                                            % else:
                                                <h4>${k}</h4>
                                                None
                                            % endif
                                        % endif
                                    </li>
                                % endfor
                                % if len(dataset['keys']) == 0:
                                    Empty
                                % endif
                            </ul>
                        </li>
                    </ul>
                % endif
            </li>
        % endfor
        </ul>

        <h3>Content</h3>
        <ul id="mycontent">
        % for iid, ds in dataset_list['content'].items():
            <li id="i${iid}">
                <a href="http://admin.hexlabel.net/browse_db/${iid}#${iid}">${ds['name']}</a>
                <div class="meta">touched: ${ds['info']['touched']}, size: ${ds['info']['size']}</div>
                % if dataset_iid and dataset_iid == iid:
                    <ul>
                        <li>
                            INFO: ${procDICT(iid, dataset['info'], no_links=True)}
                        </li>
                        <li>
                            DATA
                            <ul>
                                % for k, v in dataset['data'].items():
                                    <li>
                                        % if type(v) == type(dict()):
                                            <h4>${k}</h4>
                                            ${procDICT(iid, v, no_links=True)}
                                        % elif type(v) == type(list()):
                                            <h4>${k}</h4>
                                            ${procLIST(v)}
                                        % else:
                                            % if v:
                                                <h4><a href="http://${iid}.hexlabel.net/content/${k}">${k}</a></h4>
                                                ${v}
                                            % else:
                                                <h4>${k}</h4>
                                                None
                                            % endif
                                        % endif
                                    </li>
                                % endfor
                                % if len(dataset['keys']) == 0:
                                    Empty
                                % endif
                            </ul>
                        </li>
                    </ul>
                % endif
            </li>
        % endfor
        </ul>
    </div>
</div>

<!-- defs -->
<%def name="title()">P2P Fusion - Peerscape</%def>
<%def name="body_class()">
    admin
</%def>
<%def name="toplinks_style()">
</%def>

<%def name="procLIST(iid, l)">
    <ul>
        %for v in l:
            <li>
                % if type(v) == type(dict()):
                    ${procDICT(iid, v, no_links=True)}
                % elif type(v) == type(list()):
                    ${procLIST(iid, v)}
                % else:
                    ${v}
                % endif
            </li>
        %endfor
    </ul>
</%def>

<%def name="procDICT(iid, d, no_links=False)">
    <ul>
        %for k, v in d.items():
            <li>
                % if type(v) == type(dict()):
                    <h4>${k}</h4>
                    ${procDICT(iid, v, no_links=True)}
                % elif type(v) == type(list()):
                    <h4>${k}</h4>
                    ${procLIST(iid, v)}
                % else:
                    % if v:
                        % if no_links:
                            <h4>${k}</h4>
                            ${v}
                        % else:
                            <h4><a href="http://${iid}.hexlabel.net/content/${k}">${k}</a></h4>
                                % if v:
                                    <h4><a href="http://${iid}.hexlabel.net/content/${k}">${k}</a></h4>
                                    ${v}
                                % else:
                                    <h4>${k}</h4>
                                    None
                                % endif
                        % endif
                    % else:
                        <h4>${k}</h4>
                        None
                    % endif
                % endif
            </li>
        %endfor
    </ul>
</%def>

